cmake_minimum_required(VERSION 3.12.1)
project(linkfabric LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置输出目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# 设置头文件路径:全局性的，会影响当前目录下所有目标，可能导致不必要的污染
#include_directories(include)

# 收集源文件
set(MEMLINK_SOURCES
    src/Compression.cpp
    src/Crypto.cpp
    src/LinkFabric.cpp
    src/MemLink.cpp
    src/Message.cpp
    src/Registry.cpp
    src/RingBuffer.cpp
    src/SDK.cpp
    src/Stream.cpp
    src/StreamBuffer.cpp
    src/TLV.cpp
)

add_library(linkfabric SHARED ${MEMLINK_SOURCES})

target_include_directories(linkfabric PUBLIC ${CMAKE_SOURCE_DIR}/include)

# 示例程序
add_executable(linkfabric_example examples/sdk_demo.cpp)
target_link_libraries(linkfabric_example PRIVATE linkfabric)

# 将头文件安装到系统路径 
install(DIRECTORY include/ DESTINATION include)

# 安装动态版本
install(TARGETS linkfabric linkfabric_example
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib)

# 添加测试子目录
add_subdirectory(test)